var User = require('mongoose').model('user')
module.exports = {
  addUser: async(ctx, next) => {
    try {
      var user = ctx.request.body
      var result = await User.create(user)
      ctx.status = 200;
      ctx.body = result
    } catch (error) {
      console.log(error)
    }
  },
  update: async(param) => {
    var oldData = param.oldData;
    var newData = param.newData;
    const res = await User.update(oldData, newData)
    console.log(res)
    return res
  },
  delete: async(ctx, next) => {
    const result = await User.findByIdAndRemove(ctx.params.id)
    ctx.status = 200;
    ctx.body = result
  },
  get: async(ctx, next) => {
    const param = ctx.request.body || {}
    var result = await User.find(param)
    ctx.body = result
  },
  put: async(ctx, next) => {
    var param = ctx.request.body
    console.log(param, 32)
    const result = await User.findByIdAndUpdate({ _id: param._id }, { $set: param })
    console.log(result)
    ctx.status = 200;
    ctx.body = result;
  }
}